import java.util.Scanner;
// 完全背包问题 https://www.acwing.com/problem/content/3/
public class bag02 {

        static int N = 1010, n, V ;
        // static int [][] dp = new int [N][N];
        static int [] dp = new int [N];
        static int [] v = new int[N] , w = new int[N];
        public static void main(String [] args)
        {
            Scanner sc = new Scanner(System.in);
            n = sc.nextInt();
            V = sc.nextInt();
            for(int i = 1 ; i <= n ; i ++ )
            {
                int x = sc.nextInt();
                int y = sc.nextInt();
                v[i] = x;
                w[i] = y;
            }
            for(int i = 1; i <= n ; i ++)
                for(int j = 0 ; j <= V ; j ++  )
                {
                    // dp[j] = Math.max(dp[j],dp[j - k * v[i]] + k * w[i]);
                    if(j >= v[i])
                        dp[j] = Math.max(dp[j],dp[j-v[i]] + w[i]);
                }
            System.out.println(dp[V]);

        }

}
/**
 * import java.util.*;
 * class Main
 * {
 *     public static void main(String [] args)
 *     {
 *         Scanner sc = new Scanner(System.in);
 *         int n = sc.nextInt();
 *         int v = sc.nextInt();
 *         int [] v1 = new int[n+2];
 *         int [] w1 = new int[n+2];
 *         for(int i = 1; i <= n ; i ++)
 *         {
 *             v1[i] = sc.nextInt();
 *             w1[i] = sc.nextInt();
 *         }
 *         int [][] dp = new int[n+2][v+2];
 *         for(int i = 1; i <= n ; i ++)
 *         {
 *             for(int j = 1 ; j <= v ; j ++)
 *             {
 *                  dp[i][j] = dp[i-1][j];// 不选
 *                  if(v1[i] <= j)
 *                     dp[i][j] = Math.max(dp[i][j],dp[i][j-v1[i]] +  w1[i]);
 *
 *             }
 *         }
 *         System.out.print(dp[n][v]);
 *     }
 * }
 */
